package com.prj.ufdm.demo.tutorial.hadoop.mr;
import java.io.IOException;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

/**
 * 统计字频Reducer
 * @author Administrator
 *
 */
public class WordCountReducer extends Reducer<Text,IntWritable,Text,IntWritable> {
	
	private IntWritable result = new IntWritable();

	public void reduce(Text key, Iterable<IntWritable> values, Context context)	throws IOException, InterruptedException {
		int sum = 0;
		for (IntWritable val : values) {
			sum += val.get();
		}
		result.set(sum);
		System.out.println("\n reduce key="+key+",value="+result);
		context.write(key, result);
		
	}
}
